package com.movie.repository;

import com.movie.entity.SysUser;
import com.movie.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface SystemUserRepository extends JpaRepository<SysUser, Long> {
    
    Optional<SysUser> findByUsername(String username);
    
    Optional<SysUser> findByEmail(String email);
    
    boolean existsByUsername(String username);
    
    boolean existsByEmail(String email);
    
    // 由于User实体已改为多角色，此方法需要重新实现
    // List<User> findByRole(String role);
    
    List<SysUser> findByStatus(Boolean status);
    
    @Query("SELECT u FROM User u WHERE u.username LIKE %:keyword% OR u.email LIKE %:keyword%")
    List<SysUser> findByUsernameOrEmailContaining(@Param("keyword") String keyword);
    
    @Query("SELECT u FROM User u WHERE u.username LIKE %:keyword% OR u.email LIKE %:keyword%")
    Page<SysUser> findByUsernameOrEmailContaining(@Param("keyword") String keyword, Pageable pageable);
}